package com.arsl.client.presenter;

import com.arsl.client.PaperaziServiceAsync;
import com.arsl.client.event.KillContainerEvent;
import com.arsl.client.view.AddContentView;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasWidgets;

public class AddContentPresenter implements Presenter {

	private HandlerManager eventBus;
	private PaperaziServiceAsync rpcService;
	private AddContentView view;
	private HasWidgets container;

	public AddContentPresenter(HandlerManager eventBus,
			PaperaziServiceAsync rpcService, AddContentView view) {
		this.eventBus = eventBus;
		this.rpcService = rpcService;
		this.view = view;
		view.setPresenter(this);
	}

	@Override
	public void go(HasWidgets container) {
		this.container = container;
		container.clear();
		container.add(view);
	}

	public void killContainer() {
		eventBus.fireEvent(new KillContainerEvent(container));
	}

	public void addContent(int publisherId, String type, String title,
			String description, String url) {

		rpcService.createContent(publisherId, type, title, description, url,
				new AsyncCallback<Integer>() {

					@Override
					public void onSuccess(Integer result) {
						// TODO Auto-generated method stub

					}

					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub

					}
				});
		killContainer();
	}

}
